﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyHealthOnline.Dal.Generated.EntityClasses;
using MyHealthOnline.Dal.Generated.CollectionClasses;
using MyHealthOnline.Business;

namespace MyHealthOnline.Patient
{
    public partial class OpenQuestionnaire : System.Web.UI.Page
    {
        public int ConsultId
        {
            get
            {
                return Convert.ToInt32(Request.QueryString["ConsultId"]);
            }
        }

        public ConsultEntity Consult
        {
            get
            {
                return ConsultBusiness.GetConsult(ConsultId);
            }
        }

        public int QuestionnaireId
        {
            get
            {
                return Convert.ToInt32(Request.QueryString["QuestionnaireId"]);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var questionsDto = QuestionnaireQuestions;

                ucQuestionnaire.DataSource = questionsDto;
                ucQuestionnaire.DataBind();
            }
        }

        private QuestionCollection questionnaireQuestions = null;
        private QuestionCollection QuestionnaireQuestions
        {
            get
            {
                if (questionnaireQuestions == null)
                {
                    questionnaireQuestions = QuestionBusiness.GetQuestionnaireQuestions(QuestionnaireId);
                }
                return questionnaireQuestions;
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect(string.Format("~/Patient/ViewConsult.aspx?ConsultId={0}", ConsultId));
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            ucQuestionnaire.SaveAnswers();
            
            WebServiceHO webService = new WebServiceHO();
            webService.Notify(Consult.Pacient.Email, Consult.Specialist.Email,
                "Questionnaire completed by patient "+Consult.PacientName,
                "Questionnaire completed");

        }

    }
}